package com.spring.demo.authenticator;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;

import com.spring.demo.domain.User;
import com.spring.demo.repository.jpa.UserQueryRepository;

public class PoEntityAuditorAwareImpl implements PoEntityAuditorAware {
	
	@Autowired
	private UserQueryRepository userQueryRepository;

	public User getCurrentAuditor() {
		System.out.println("asdasdasdasd:"+SecurityContextHolder.getContext().getAuthentication().getPrincipal());
		org.springframework.security.core.userdetails.User currentUser 
			= (org.springframework.security.core.userdetails.User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
		String currentUserId = currentUser.getUsername();
		return userQueryRepository.findByLoginName(currentUserId);
	}

	public String getCurrentAuditorId() {
		org.springframework.security.core.userdetails.User currentUser 
			= (org.springframework.security.core.userdetails.User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
		String currentUserId = currentUser.getUsername();
		return currentUserId;
	}

}
